package com.internetCafes.spms.web.customer.controller;

import com.internetCafes.spms.common.base.BaseWebController;
import com.internetCafes.spms.common.module.excel.ExcelUtils;
import com.internetCafes.spms.common.utils.entity.RR;
import com.internetCafes.spms.common.utils.entity.page.PageItemDTO;
import com.internetCafes.spms.common.utils.entity.page.PageItemVO;
import com.internetCafes.spms.core.annotation.SysLog;
import com.internetCafes.spms.web.customer.bizservice.customer.IEntCustomerFlowBizService;
import com.internetCafes.spms.web.customer.model.customer.flow.CustomerFlowPagingReq;
import com.internetCafes.spms.web.customer.model.customer.flow.CustomerFlowPagingRes;
import com.internetCafes.spms.web.customer.model.customer.flow.FlowExcel;
import com.internetCafes.spms.web.customer.model.customer.flow.FlowExcelReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 客户信息表 前端控制器
 */
@RestController
@RequestMapping("/ent/customer/flow")
public class EntCustomerFlowController extends BaseWebController {

    @Autowired
    private IEntCustomerFlowBizService flowBizService;

    /**
     * 导出
     */
    @PostMapping("/export")
    public void export(@RequestBody FlowExcelReq req, HttpServletResponse response) {
        List<FlowExcel> flowExcels =
                flowBizService.flowExcelExport(req);
        ExcelUtils.exportExcel(flowExcels, "流转记录", "流转记录", FlowExcel.class, "流转记录.xls", response);
    }

    /**
     * 分页
     */
    @PostMapping("/paging")
    public RR<PageItemVO<CustomerFlowPagingRes>> paging(@RequestBody PageItemDTO<CustomerFlowPagingReq> req) {
        return RR.success(flowBizService.paging(req));
    }

    /**
     * 移除
     */
    @SysLog("移除")
    @PutMapping("/remove/{customerId}")
    public RR<Void> remove(@PathVariable Long customerId) {
        return flowBizService.remove(customerId) ? RR.success() : RR.fail();
    }

    /**
     * 转意向
     */
    @SysLog("转意向")
    @PutMapping("/interest/{customerId}")
    public RR<Void> interest(@PathVariable Long customerId) {
        return flowBizService.interest(customerId) ? RR.success() : RR.fail();
    }

//   @SysLog("转成交")
//    @PutMapping("/deal/{customerId}")
//    public RR<Void> deal(@PathVariable Long customerId) {
//        return flowBizService.deal(customerId) ? RR.success() : RR.fail();
//    }
}
